import type { RequestData } from '@ant-design/pro-table';
import { request } from 'umi';
import { orderList } from '../information/types';

//获取优惠券详细信息
export async function getOrderDetail(templateId?: string) {
  return await request('/coupon/template/info', {
    params: {
      templateId,
    },
  });
}

//订单列表
export async function getOrderTable(params: any): Promise<RequestData<orderList>> {
  return await request('/coupon/template/page', {
    params: {
      // ...params,
      page: params.current,
      pageSize: params.pageSize,
      // tenant_id: params.tenant ? params.tenant?.id : '',
    },
  });
}

//下架优惠券
export async function deleteTemplate(templateId: string): Promise<RequestData<never>> {
  return await request(`/coupon/template/delete`, {
    method: 'POST',
    params: {
      templateId,
    },
  });
}

//删除优惠券
export async function downCouponTemplate(templateId: string): Promise<RequestData<never>> {
  return await request(`/coupon/template/down`, {
    method: 'POST',
    params: {
      templateId,
    },
  });
}

//创建优惠券模板
export async function addTemplateItem(params: any): Promise<any> {
  return await request('/coupon/template/create', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

//获取优惠卷详情
export async function getTemplateDetail(templateId: string): Promise<any> {
  return await request('/coupon/template/info', {
    params: {
      templateId,
    },
  });
}
//使用优惠券模板进行派送
export async function couponTemplateItem(params: any): Promise<any> {
  return await request('/coupon/template/distribute', {
    method: 'POST',
    params: { templateId: params.templateId },
    data: {
      phones: params.phones,
    },
  });
}
